package com.kim.rssreader;

import android.app.Application;
import android.util.Log;

import com.kim.rssreader.db.DBDAO;

public class RssApplication extends Application implements
		Thread.UncaughtExceptionHandler {

	public static final String TAG = "RssApplication";

	private DBDAO applicationDbDAO;

	StringBuffer phoneInfo;// 手机相关信息

	@Override
	public void onCreate() {
		super.onCreate();
		// Thread.setDefaultUncaughtExceptionHandler(this);
		applicationDbDAO = DBDAO.getInstance(getApplicationContext());
		phoneInfo = new StringBuffer();
		phoneInfo.append("Product: " + android.os.Build.PRODUCT);
		phoneInfo.append(", CPU_ABI: " + android.os.Build.CPU_ABI);
		phoneInfo.append(", TAGS: " + android.os.Build.TAGS);
		phoneInfo.append(", VERSION_CODES.BASE: "
				+ android.os.Build.VERSION_CODES.BASE);
		phoneInfo.append(", MODEL: " + android.os.Build.MODEL);
		phoneInfo.append(", SDK: " + android.os.Build.VERSION.SDK);
		phoneInfo.append(", VERSION.RELEASE: " + android.os.Build.VERSION.RELEASE);
		phoneInfo.append(", DEVICE: " + android.os.Build.DEVICE);
		phoneInfo.append(", DISPLAY: " + android.os.Build.DISPLAY);
		phoneInfo.append(", BRAND: " + android.os.Build.BRAND);
		phoneInfo.append(", BOARD: " + android.os.Build.BOARD);
		phoneInfo.append(", FINGERPRINT: " + android.os.Build.FINGERPRINT);
		phoneInfo.append(", ID: " + android.os.Build.ID);
		phoneInfo.append(", MANUFACTURER: " + android.os.Build.MANUFACTURER);
		phoneInfo.append(", USER: " + android.os.Build.USER);

		Log.i(TAG, phoneInfo.toString());
	}

	@Override
	public void onLowMemory() {
		System.runFinalization();
		System.gc();
		super.onLowMemory();
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
	}

	public DBDAO getDbDAO() {
		return applicationDbDAO;
	}

	@Override
	public void uncaughtException(Thread thread, Throwable ex) {

		String threadName = thread.getName();
		String errorMsg = ex.getLocalizedMessage();
		Log.e(TAG, threadName + ":" + errorMsg);
		ex.printStackTrace();
	}

}
